/*
 * Copyright 1999,2004 The Apache Software Foundation.
 * 
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 * 
 *      http://www.apache.org/licenses/LICENSE-2.0
 * 
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package com.dotfunny;

import java.io.IOException;
import java.io.PrintWriter;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.util.*;
import com.sun.syndication.feed.synd.*;

/**
 * 
 * TODO:
 *
 * 2. parse quote
 * 4. CSS
 *
 */

public final class Hello extends HttpServlet {


    /**
     * Respond to a GET request for the content produced by
     * this servlet.
     *
     * @param request The servlet request we are processing
     * @param response The servlet response we are producing
     *
     * @exception IOException if an input/output error occurs
     * @exception ServletException if a servlet error occurs
     */
	
	//private final String _url = "http://science.slashdot.org/comments.pl?threshold=4&mode=flat&commentsort=3&op=Change&sid=205557";
	//private final String _url = "http://rss.slashdot.org/~r/Slashdot/slashdot/~3/56834150/article.pl";
	
    public void doGet(HttpServletRequest request,
                      HttpServletResponse response)
      throws IOException, ServletException {

	response.setContentType("text/html");
	PrintWriter writer = response.getWriter();
	RSSParser parser  = new RSSParser("http://rss.slashdot.org/Slashdot/slashdot");
	List list = parser.getEntries();
	Iterator i = list.iterator();
	SyndEntry tempEntry;
	
	writer.println("<html>");
	writer.println("<head>");
	writer.println("<title>Dot Funny!</title>");
	writer.println("<link rel=\"stylesheet\" type=\"text/css\" href=\"mystyle.css\" />");
	//writer.println("<style type=\"text/css\"> body {background-color: yellow} } </style>");
	writer.println("</head>");
	writer.println("<body>");
	while (i.hasNext())
	{
		tempEntry = (SyndEntry)i.next();
		writer.println("<div id=\"dotfunny_title\">"+tempEntry.getTitle()+"</div>");
		writer.println("<div id=\"dotfunny_desc\">"+tempEntry.getDescription().getValue()+"</div><br>");
		Engine e = new Engine(tempEntry.getLink().toString(), "Funny", 5);
		writer.println(e.doWork()+"<br>");
	}
	writer.println("</body>");
	writer.println("</html>");

    }
    public static void main(String args[])
    {
    	System.out.println("Hello's unit test...");
    }
}
